package com.it.mybatisplus.controller;

import com.it.mybatisplus.entity.User;
import com.it.mybatisplus.service.UserService;
import com.it.mybatisplus.tools.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 羡羡
 * @Date: 2022/05/25/09:43
 */
@RestController
public class TestController {

    @Autowired
    UserService user;

    /**
     * 返回所有的数据
     * @return
     */
    @RequestMapping(path = "/index",method = RequestMethod.GET)
    public JsonResult test(){
        return  user.seall();
    }

    /**
     * 通过ID查询指定数据
     * @param id ID
     * @return
     */
    @RequestMapping(path = "/user/{id}",method = RequestMethod.GET)
    public JsonResult test2(@PathVariable("id") Integer id){
        return user.seonuser(id);
    }

    /**
     * 添加一条记录
     * @param usrn
     * @return
     */
    @RequestMapping(path = "/adduser",method = RequestMethod.POST)
    public JsonResult test3(User usrn){
        return user.addone(usrn);
    }


    /**
     * 删除一条记录
     * @param id
     * @return
     */
    @RequestMapping(path = "/del/{id}",method = RequestMethod.GET)
    public JsonResult test4(@PathVariable("id") Integer id){
        return  user.delone(id);
    }

    /**
     * 更新数据
     * @param usen
     * @return
     */
    @RequestMapping(path = "/upuser",method = RequestMethod.PUT)
    public JsonResult test5(User usen){
        return user.upone(usen);
    }

    /**
     * 统计数量
     * @return
     */
    @RequestMapping(path = "/coun",method = RequestMethod.GET)
    public JsonResult test6(){
        return  user.counnumber();
    }

    /**
     * 模糊查询like
     * @param name
     * @return
     */
    @RequestMapping(path = "/like/{name}",method = RequestMethod.GET)
    public JsonResult test7(@PathVariable("name") String name){
        return user.likelist(name);
    }
}
